package com.google.coffeeshop.gui.desktop.orderpayment;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JPanel;

import vn.bang.utility.LongUtil;

import com.google.coffeeshop.business.ManagerBusiness;
import com.google.coffeeshop.business.OrderBusiness;
import com.google.coffeeshop.entity.EmployeeDTO;
import com.google.coffeeshop.entity.SeatDTO;
import com.google.coffeeshop.gui.desktop.SwingFactory;
import com.google.coffeeshop.gui.desktop.selfcomponent.LRItem;

public class SeatChoosingForStopPanel extends JPanel {
	private JComboBox multiColumnsComboBox = SwingFactory.createMultiColumnsComboBox();
	private List<SeatDTO> seats = OrderBusiness.findAllUsableSeats(); 
	
	public SeatChoosingForStopPanel() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JComboBox comboBox = multiColumnsComboBox;
		comboBox.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
//				LRItem item = (LRItem)e.getItem();
//				if (item != null) {
//					long id = LongUtil.parseLong(item.getRightText());
//					EmployeeDTO employee = ManagerBusiness.findEmployeeWorkingById(id);
//					if (employee != null) {
//					}
//				}
			}
		});
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.insets = new Insets(0, 0, 5, 0);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 0;
		gbc_comboBox.gridy = 0;
		add(comboBox, gbc_comboBox);
		
		addData();
	}
	
	public Long getChosenSeatId() {
		if (multiColumnsComboBox != null) {
			LRItem item = (LRItem)multiColumnsComboBox.getSelectedItem();
			return LongUtil.valueOf(item.getRightText());
		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	private void addData() {
		
		if (seats != null && !seats.isEmpty()) {
			DefaultComboBoxModel<LRItem> model = new DefaultComboBoxModel<LRItem>();
			for (SeatDTO seat : seats) {
				model.addElement(new LRItem(seat.getCode(), String.valueOf(seat.getId())));
			}
	        multiColumnsComboBox.setModel(model);
		}
	}
	
	private static final long serialVersionUID = 1L;

}
